package com.mall.vo;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单VO
 * 
 * @author Mall Team
 */
@Data
public class OrderVO {
    
    private Long id;
    private String orderNo;
    private Long userId;
    private String username;
    private BigDecimal totalAmount;
    private BigDecimal paymentAmount;
    private Integer status;
    private String statusDesc;
    private String receiverName;
    private String receiverPhone;
    private String receiverAddress;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    // 订单商品列表
    private List<OrderItemVO> orderItems;
    
    /**
     * 订单商品VO
     */
    @Data
    public static class OrderItemVO {
        private Long id;
        private Long orderId;
        private Long productId;
        private String productName;
        private String productImage;
        private BigDecimal price;
        private Integer quantity;
        private BigDecimal totalAmount;
    }
    
    /**
     * 订单列表VO（简化版）
     */
    @Data
    public static class OrderListVO {
        private Long id;
        private String orderNo;
        private BigDecimal totalAmount;
        private Integer status;
        private String statusDesc;
        private Integer itemCount;  // 商品数量
        private LocalDateTime createTime;
        
        // 第一个商品信息
        private String firstProductName;
        private String firstProductImage;
    }
    
    /**
     * 订单详情VO
     */
    @Data
    public static class OrderDetailVO {
        private Long id;
        private String orderNo;
        private Long userId;
        private String username;
        private BigDecimal totalAmount;
        private BigDecimal paymentAmount;
        private Integer status;
        private String statusDesc;
        private String receiverName;
        private String receiverPhone;
        private String receiverAddress;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;
        
        // 订单商品详情
        private List<OrderItemVO> orderItems;
        
        // 操作权限
        private Boolean canCancel;  // 是否可以取消
        private Boolean canPay;     // 是否可以支付
        private Boolean canConfirm; // 是否可以确认收货
    }
    
    /**
     * 设置状态描述
     */
    public void setStatusDesc() {
        if (this.status != null) {
            switch (this.status) {
                case 1:
                    this.statusDesc = "待付款";
                    break;
                case 2:
                    this.statusDesc = "已付款";
                    break;
                case 3:
                    this.statusDesc = "已发货";
                    break;
                case 4:
                    this.statusDesc = "已完成";
                    break;
                case 5:
                    this.statusDesc = "已取消";
                    break;
                default:
                    this.statusDesc = "未知状态";
                    break;
            }
        }
    }
    
    /**
     * 计算商品总数量
     */
    public Integer getTotalQuantity() {
        if (orderItems == null || orderItems.isEmpty()) {
            return 0;
        }
        return orderItems.stream().mapToInt(OrderItemVO::getQuantity).sum();
    }
}